package com.lee.rpc.protocal.netty.handler;
 
import com.lee.rpc.protocal.core.RequestHolder;
import com.lee.rpc.protocal.core.RpcFuture;
import com.lee.rpc.protocal.core.RpcProtocal;
import com.lee.rpc.protocal.core.RpcResponse;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class ClientHandler extends SimpleChannelInboundHandler<RpcProtocal<RpcResponse>>{

	@Override
	protected void channelRead0(ChannelHandlerContext ctx, RpcProtocal<RpcResponse> msg) throws Exception {
		// TODO Auto-generated method stub 
		//这个连接已完成了,要删除
		long requestId = msg.getHeader().getRequestId();
		RpcFuture<RpcResponse> future =  RequestHolder.REQUEST_MAP.remove(requestId);
		// setSuccess(msg.getContent())通过这个方法唤醒get()方法获取到服务端返回的数据
		// 数据就是通过setSucess方法设置的数据msg.getContent()
		future.getPromiss().setSuccess(msg.getContent());
		
	}

}
